package com.zzt.zt_autocompletetextview;

import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;

import androidx.appcompat.widget.AppCompatAutoCompleteTextView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author: zeting
 * @date: 2022/9/26
 */
public class MyRecycleAdapter extends BaseRecyclerAdapter<String, BaseRecyclerViewHolder> {
    public MyRecycleAdapter(List<String> data) {
        super(data);
    }

    @Override
    public int getItemLayoutId(int viewType) {
        return R.layout.layout_recycle_edit_auto;
    }

    @Override
    protected void bindTheData(BaseRecyclerViewHolder holder, String data) {
        MyAutoCompleteTextView aatv_input = holder.get(R.id.aatv_input);
        LinearLayout ll_bg = holder.get(R.id.ll_bg);
        ll_bg.setBackgroundColor(RandColor());
// 初始化数据
        final ArrayList<Language> languages = new ArrayList<>();
        Language one = new Language();
        one.name = "Java";
        languages.add(one);

        Language two = new Language();
        two.name = "lkjhgf";
        languages.add(two);

        Language three = new Language();
        three.name = "dfxgchv";
        languages.add(three);

        Language four = new Language();
        four.name = "wert";
        languages.add(four);

        Language five = new Language();
        five.name = "sdezfdgtfyguhi";
        languages.add(five);

        Language six = new Language();
        six.name = "erxtcyvbuinomp";
        languages.add(six);
        MyAutoAdapter myAdapter = new MyAutoAdapter(mContext, R.layout.item_auto, languages);
        aatv_input.setAdapter(myAdapter);
        aatv_input.setOnClickListener(new OnSignleClickListener() {
            @Override
            public void onSignleClick(View v) {
                aatv_input.showDropDown();
            }
        });
        aatv_input.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Language language = myAdapter.getItem(position);
                MyAutoCompleteTextView inputText = holder.get(R.id.aatv_input);
                inputText.setText(language.name);
                inputText.setSelection(language.name.length());
            }
        });
    }

    //随机色
    public static int RandColor() {
        // 随机颜色
        Random random = new Random();
        int ranColor = 0xff000000 | random.nextInt(0x00ffffff);
        return ranColor;
    }

}
